import sys

# ----------------------------------------------------

import wx
import wx.aui
import wx.py 
import wx.glcanvas
import wx.lib.flatnotebook as fnb

from demoEnginePython import *

#---------------------------------------------------------------------------

class TestFrame(wx.Frame):
    def __init__(self, parent=None, ID=-1, title='pyOSG' ):
        wx.Frame.__init__(self, parent, ID, title)
        
        #-- shell---------------------------------------------
        self.shell = wx.py.shell.Shell(self, -1, introText="",style =wx.NO_BORDER)

        # --- OSG ---------------------------------
        self.root = Node()
        print self.root.Load("axes.osg")

        self.node = Node(self.root)
        self.node.Scale(0.1)
        print self.node.Load("cow.osg")

        self.viewerPanel = wx.glcanvas.GLCanvas(self,-1)
        self.viewer = Viewer( self.viewerPanel.GetHandle() )
        self.viewer.SetRoot(self.root)

        globals()['r'] = self.root
        globals()['n'] = self.node 
        globals()['v'] = self.viewer
        globals()['c'] = self.viewer.GetCamera()
        globals()['m'] = self.viewer.GetManipulator()
        
        # --- Timer ---------------------------------
        self.timer = wx.Timer(self,-1)
        self.timer.Start(1) 

        # --- Layout ---------------------------------
        self.SetSize(wx.Size(600,900))
        self._mgr = wx.aui.FrameManager()
        self._mgr.SetManagedWindow(self)
        self._mgr.GetArtProvider().SetColor(wx.aui.AUI_ART_INACTIVE_CAPTION_COLOUR, wx.Color(0,150,255)) 
        self._mgr.GetArtProvider().SetColor(wx.aui.AUI_ART_INACTIVE_CAPTION_GRADIENT_COLOUR, wx.Color(0,80,255)) 
        self._mgr.GetArtProvider().SetColor(wx.aui.AUI_ART_INACTIVE_CAPTION_COLOUR, wx.Color(80,150,255)) 
        self._mgr.GetArtProvider().SetColor(wx.aui.AUI_ART_INACTIVE_CAPTION_GRADIENT_COLOUR, wx.Color(80,150,255)) 

        self._mgr.AddPane(self.viewerPanel, wx.aui.PaneInfo().
                        Name("CenterPane").CenterPane())

        self._mgr.AddPane(self.shell, wx.aui.PaneInfo().
                        Name("shell").Caption("shell").Bottom().
                        BestSize(wx.Size(200,300)).MinSize(wx.Size(200,100)))
        
        self._mgr.Update()

        # --- Bindings ---------------------------------
        self.Bind(wx.EVT_CLOSE, self.OnClose)
        self.Bind(wx.EVT_TIMER, self.OnTimer, id=self.timer.GetId() )
                
    def OnClose(self, event):
        #self.viewer.setSceneData(None)
        self.timer.Stop()
        self.node = None
        self.viewer = None
        self.Destroy()
        
    def OnTimer(self,e):
        self.viewer.Frame()
        
#---------------------------------------------------------------------------

class TestApp(wx.App):
    def OnInit(self):
        self.frame = TestFrame()
        self.SetTopWindow(self.frame)
        self.frame.Show() 
        return True
   
#---------------------------------------------------------------------------

if __name__ == '__main__':
    app = TestApp(0)
    app.MainLoop()
    
    

